#----------------------------
# Name: Aaron Carson
# Project: Madlibs.py
# Period: 2
# Start Date: 9/17/2013
# Last Revision Date: 10/7/2013
# Version: 1.2.0
#----------------------------

swearFilter = ["dumb",
               "stupid",
               "retard",
               "crap",
               "poop",
               "anal beads",
               "anal",
               "shit",
               "ass",
               "ballsack",
               "balls",
               "bastard",
               "bitch",
               "biatch",
               "blowjob",
               "blow job",
               "bollock",
               "bollok",
               "boner",
               "cock",
               "swag"]
             
def displayStartScreen():
    print "Madlibs"
    raw_input("Press Enter to Continue")
    
def displayEndScreen():
    print "Goodbye"
    raw_input("Press Enter to Exit")

def getMenuOption(maxOption):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter Number or Q> ")
        option = option.upper()
        for num in range(1, maxOption+1):
            if option == str(num):
                goodOption = True
        if option == 'Q':
            goodOption = True
        if not goodOption:
            print "Please pick a valid option!"
    return option
        
def menu(options):
    print "------Please Select a Story------"
    print " [1] The End of the Day"
    print " [2] My New Pet"
    print " [3] The Quest"
    print " [Q] Quit"
    print "----------------------------------"
    option = getMenuOption(options)
    return option
    
def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearFilter:
            if not wordtest(word, "swag"):
                if not wordtest(word, "sweg"):
                    if not wordtest(word, "5weg"):
                        goodWord = True
        else:
            print "Do you kiss your mother with that mouth?"
        if not goodWord:
            print "Try again"
    return word
    
def getNumber(prompt, max = "", min = ""):
    num = ""
    goodNum = False
    while not goodNum:
        isNum = True
        num = raw_input(prompt)
        for character in num:
            if character not in "0123456789":
                isNum = False
        if min != "":
            if isNum:
                if float(num) < min:
                    isNum = False
        if max != "":
            if isNum:
                if float(num) > max:
                    isNum = False
        if isNum:
            goodNum = True
        else:
            print "Not a valid number, try again."
    return num
    
def wordtest(string, word):    
    found = False
    testChar=0
    for char in string:
        #print char, word[testChar]
        if char == word[testChar]:
            if testChar < len(word):
                testChar += 1
            else:
                found = True
        if testChar == len(word):
            found = True
        return found
        
def story1():
    place1 = getWord("Enter a place: ")
    name = getWord("Enter a name: ")
    thing1 = getWord("Enter a thing: ")
    event = getWord("Enter a social event: ")
    thing2 = getWord("Enter a thing that may or may not be related to the social event: ")
    creature = getWord("Enter a race of creatures: ")
    thing3 = getWord("Enter a third thing: ")  
    story = "It was near the end of the day at "
    story += place1 + ", and " + name + " was getting ready for the " + event + ". " 
    story += name + " knew that all of the " + creature +" would be there. " 
    story += name + " needed to be prepared. " + name + " brought a " + thing1 +", a " 
    story += thing2 + " and a " + thing3 +". "
    story += "The " + event + " ended in disaster."
    
    print story
    
def story2():
    name = getWord("Enter a name: ")
    age = getNumber("Enter a number: ")
    item = getWord ("Enter an item: ")
    animal = getWord("Enter an animal: ")
    verb = getWord("Enter a verb: ")
    heshe = getWord("He or she: ")
    story = "I got a new pet and I named it"
    story += " " + name + ". "
    story += "I think " + name + " is"
    story += " a " + age + " year old " + animal + ". "
    story += " I taught " + name + " how to " + verb + ". " + name
    story += " is the greatest pet ever. "
    story += "  Except when he eats my things. I almost sold "+ name +" when "+ heshe
    story += " ate my " + item + "."
    
    
    print story
    
def thequest():
    name = getWord("Enter a name: ")
    title = getWord("Enter a title ex;Destroyer of Worlds. :")
    thing = getWord("Enter a thing: ")
    di = getWord("Enter a dessert item: ")
    inn = getWord("Enter a name: ")
    adj = getWord("Enter an adjective: ")
    timeperiod = getWord("Enter a plural measurement of time: ")
    fd = getWord("Enter a food item: ")
    adj2 = getWord("Enter an adjective: ")
    pay = getWord("Enter a form of payment: ")
    adj3 = getWord("Enter an adjective: ")
    ty = getWord("Enter a noun: ")
    noun = getWord("Enter a noun: ") 
    verrb = getWord("Enter a verb: ")
    noun1 = getWord("Enter a noun: ")
    adj4 = getWord("Enter an adjective: ")
    player = name + " " + title + ","
    story= name + ', ' + title + " in,  The Quest for the " + adj + " " + thing + "!"
    story += " " + player + " travelled for " + timeperiod + ", through " + adj2 
    story += " "+noun + "s and " + adj3 +" " + noun1 +"s."
    story += " Finally, " + player + " stopped to rest at " +inn+ "'s inn."
    story += " Not long after " + name + " arrived, "+ name + " was approached by "
    story += "a " + adj4 + " inn wench. She offered him " + fd + " and " +di + ". "
    story += name + " happily accepted them and then decided to give her " + pay 
    story += " as payment. The wench did not accept and slit " + name + "'s throat. "
    story += player + " was dead. His spirit haunted the wenches son for 3  " 
    story += timeperiod + ". " +name+ " possesed his "+ ty + " , causing it to " + verrb
    story += " and explode."
    
    print story
    
    
    
def run():
    displayStartScreen()
    choice = ""
    while choice != 'Q':
        choice = menu(3)
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            thequest ()
        elif choice == 'Q':
            displayEndScreen()
        else:
            print "Something Awful Ocurred...yell at programmer!"
    exit()
run()
